package com.inspur.myapplication.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.inspur.myapplication.R;
import com.inspur.myapplication.dao.UserDao;
import com.inspur.myapplication.entity.UserBean;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    public void loginClick(View view){
        //接收用户的数据，调用模型层的功能
        EditText editText=(EditText)findViewById(R.id.login_username);
        String userName=editText.getText().toString();
        editText=(EditText)findViewById(R.id.login_password);
        String password=editText.getText().toString();

        UserBean userBean=new UserBean();
        userBean.setUserName(userName);
        userBean.setPassword(password);

        UserDao userDao=new UserDao(this);
        userBean=userDao.checkLogin(userBean);
        if(userBean==null){
            Toast.makeText(this,"fail",Toast.LENGTH_LONG).show();

        }else {
            Toast.makeText(this,"succ",Toast.LENGTH_LONG).show();
            UserBean.currentUserName=userName;
        }
    }
}
